package com.vito.oa.act.event.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.vito.base.model.MyHashMap;
import com.vito.base.util.Contants;
import com.vito.oa.act.event.service.ActivitiEvent;
import com.vito.oa.act.event.service.EventPublisherService;
import com.vito.oa.act.event.service.OaActEventPublisherService;
import com.vito.oa.act.extend.service.OaActProgressTableService;

@Service
public class OaActEventPublisherServiceImpl implements OaActEventPublisherService {
	private static Logger log = LoggerFactory.getLogger(OaActEventPublisherServiceImpl.class);
	@Autowired
	private OaActProgressTableService actProgressTableService;
	@Autowired
	private EventPublisherService eventPublisher;
	
	@SuppressWarnings("unchecked")
	@Override
	public void sendActEvent(String businessId,String sysKey, String processKey,String status) {
		try {
			Map<String, Object> formList = actProgressTableService.queryBussInfo(processKey,
					Contants.FORM_PROCESS_START, businessId, Contants.FORM_PROCESS_MAIN_TASKID);

			List<MyHashMap<String, Object>> main = (List<MyHashMap<String, Object>>) formList
					.get(Contants.FORM_KEY_MAIN);
			List<MyHashMap<String, Object>> subs = (List<MyHashMap<String, Object>>) formList
					.get(Contants.FORM_KEY_SUBS);
			MyHashMap<String, Object> tab = (MyHashMap<String, Object>) main.get(0).get(Contants.FORM_KEY_TAB);
			String startUserId = (String) tab.get("userid");
			
			ActivitiEvent event = new ActivitiEvent(sysKey,processKey,startUserId,businessId,main,subs,status);
			eventPublisher.sendMessage(event);
			log.info("审批单bussid={}发送消息成功",businessId);
		} catch (Exception e) {
			log.error("审批消息-查询表单异常",e);
		}
	}

}
